package ee.siimkaspar.subjects.model;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;

@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@Entity
@Table(name = "subject_attribute_type")
public class SubjectAttributeType implements Serializable, ModelInterface {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "subject_attribute_type", unique = true, nullable = false)
	private Integer id;
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "subject_type_fk")
	private SubjectType subjectType;
	@Column(name = "type_name", length = 200)
	private String typeName;
	@Column(name = "data_type")
	private Integer dataType;
	@Column(name = "orderby")
	private Integer orderby;
	@Column(name = "required", length = 1)
	private String required;
	@Column(name = "multiple_attributes", length = 1)
	private String multipleAttributes;
	@Column(name = "created_by_default", length = 1)
	private String createdByDefault;
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "subjectAttributeType")
	private List<SubjectAttribute> subjectAttributes = new ArrayList<SubjectAttribute>();

	public SubjectAttributeType() {
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public SubjectType getSubjectType() {
		return this.subjectType;
	}

	public void setSubjectType(SubjectType subjectType) {
		this.subjectType = subjectType;
	}

	public String getTypeName() {
		return this.typeName;
	}

	public void setTypeName(String typeName) {
		this.typeName = typeName;
	}

	public Integer getDataType() {
		return dataType;
	}

	public void setDataType(Integer dataType) {
		this.dataType = dataType;
	}

	public Integer getOrderby() {
		return this.orderby;
	}

	public void setOrderby(Integer orderby) {
		this.orderby = orderby;
	}

	public String getRequired() {
		return this.required;
	}

	public void setRequired(String required) {
		this.required = required;
	}

	public String getMultipleAttributes() {
		return this.multipleAttributes;
	}

	public void setMultipleAttributes(String multipleAttributes) {
		this.multipleAttributes = multipleAttributes;
	}

	public String getCreatedByDefault() {
		return this.createdByDefault;
	}

	public void setCreatedByDefault(String createdByDefault) {
		this.createdByDefault = createdByDefault;
	}

	public List<SubjectAttribute> getSubjectAttributes() {
		return subjectAttributes;
	}

	public void setSubjectAttributes(List<SubjectAttribute> subjectAttributes) {
		this.subjectAttributes = subjectAttributes;
	}
	

	@Override
	public String toString() {
		return "SubjectAttributeType [id=" + id + ", typeName=" + typeName
				+ ", dataType=" + dataType + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((dataType == null) ? 0 : dataType.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((required == null) ? 0 : required.hashCode());
		result = prime * result
				+ ((typeName == null) ? 0 : typeName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SubjectAttributeType other = (SubjectAttributeType) obj;
		if (dataType == null) {
			if (other.dataType != null)
				return false;
		} else if (!dataType.equals(other.dataType))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (required == null) {
			if (other.required != null)
				return false;
		} else if (!required.equals(other.required))
			return false;
		if (typeName == null) {
			if (other.typeName != null)
				return false;
		} else if (!typeName.equals(other.typeName))
			return false;
		return true;
	}
	@Override
	public boolean validate() {
		// TODO Auto-generated method stub
		return true;
	}
}
